package com.ourteam.system.dao.impl;

import com.ourteam.system.dao.ISysEventLogTypeDAO;
import com.ourteam.system.dao.SysEventLogType;
import com.ourteam.system.dao.SysEventLogTypeDAOQueryBean;

import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;

import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * Template Name : DAO服务对象
 * Template Version : 1
 * Template Last Modfiy Date : Fri Nov 17 11:00:11 CST 2017
 * Auto Generate Date : 2018-07-31 15:13:39
  * Warning ! This file will be overwrite when regenerate !
  *
 */
public class AbstractSysEventLogTypeDAOJdbcImpl extends AbstractSpringDAO
    implements ISysEventLogTypeDAO {
    public static final String[] ENTITY_FIELDS = new String[] {
            Id, EventTypeCode, EventTypeName, Status, Remarks,
            EventContentTemplate, EventDomainId, EventDomainName
        };
    public static final String[] ENTITY_PROPERTIES = new String[] {
            _DataObjectProperty.Id, _DataObjectProperty.EventTypeCode,
            _DataObjectProperty.EventTypeName, _DataObjectProperty.Status,
            _DataObjectProperty.Remarks,
            _DataObjectProperty.EventContentTemplate,
            _DataObjectProperty.EventDomainId,
            _DataObjectProperty.EventDomainName
        };
    public static final String[] ENTITY_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {
            EventTypeCode, EventDomainId
        };
    private static String relatedJoinSQL = null;
    private static String basicFilterSQL = null;
    private DataAccessObjectHelper<SysEventLogType, SysEventLogTypeDAOQueryBean> daoHelper;

    public AbstractSysEventLogTypeDAOJdbcImpl() {
        super();
        daoHelper = new DataAccessObjectHelper<SysEventLogType, SysEventLogTypeDAOQueryBean>(this);
    }

    protected String getEntityName() {
        return EntityName;
    }

    protected String[] getEntityFields() {
        return ENTITY_FIELDS;
    }

    protected String[] getEntityProperties() {
        return ENTITY_PROPERTIES;
    }

    protected String[] getEntityPKFields() {
        return ENTITY_PK_FIELDS;
    }

    protected String[] getEntityAutoGenPKFields() {
        return ENTITY_AUTO_GEN_PK_FIELDS;
    }

    protected String[] getEntityUniqueFields() {
        return ENTITY_UNIQUE_FIELDS;
    }

    protected String getBaiscQueryFilter() {
        if (basicFilterSQL == null) {
            StringBuffer basicFilterSQLbuffer = new StringBuffer();

            basicFilterSQL = basicFilterSQLbuffer.toString();
        }

        return basicFilterSQL;
    }

    protected String getRelatedJoinSQL() {
        if (relatedJoinSQL == null) {
            StringBuffer relatedJoinSQLBuffer = new StringBuffer();

            relatedJoinSQLBuffer.append(" LEFT JOIN ")
                                .append(com.ourteam.system.dao.ISysDomainDAO.EntityName)
                                .append(" SYS_DOMAIN ");

            relatedJoinSQLBuffer.append(" ON ( ");

            relatedJoinSQLBuffer.append(StringUtils.replace(
                    com.ourteam.system.dao.ISysDomainDAO.Id,
                    com.ourteam.system.dao.ISysDomainDAO.EntityName + ".",
                    "SYS_DOMAIN."));
            relatedJoinSQLBuffer.append(" = ").append(EventDomainId);

            relatedJoinSQLBuffer.append(" ) ");

            relatedJoinSQL = relatedJoinSQLBuffer.toString();
        }

        return relatedJoinSQL;
    }

    /**
         * Check Data Unique
         * @param aSysEventLogType
         * @throws Exception
         */
    public boolean checkIsUnique(SysEventLogType aSysEventLogType)
        throws Exception {
        if (aSysEventLogType == null) {
            return true;
        }

        List valueList = new ArrayList();

        List pkValueList = new ArrayList();

        pkValueList.add(aSysEventLogType.getId());

        valueList.add(aSysEventLogType.getEventTypeCode());

        valueList.add(aSysEventLogType.getEventDomainId());

        return isUnique(valueList.toArray(new Object[valueList.size()]),
            pkValueList.toArray(new Object[pkValueList.size()]));
    }

    /**
     * Insert Data
     * @param aSysEventLogType
     * @throws Exception
     */
    public void insert(SysEventLogType aSysEventLogType)
        throws Exception {
        super.doInsert(aSysEventLogType);
    }

    /**
         * Batch Insert Datas
         * @param aSysEventLogType
         * @throws Exception
         */
    public void batchInsert(SysEventLogType[] aSysEventLogTypes)
        throws Exception {
        super.doBatchInsert(aSysEventLogTypes);
    }

    /**
         * Delete Data
         * @param  final long id         *
         * @throws Exception
         */
    public void delete(final long id) throws Exception {
        super.doDeleteById(new Object[] { new Long(id) });
    }

    /**
     * Delete Datas
     * @param queryBean
     * @throws Exception
     */
    public void delete(SysEventLogTypeDAOQueryBean queryBean)
        throws Exception {
        super.doDeleteByQuery(queryBean);
    }

    public void delete(SysEventLogType aSysEventLogType)
        throws Exception {
        delete(aSysEventLogType.getId());
    }

    /**
     * Update Data Selective
     * @param aSysEventLogType
     * @throws Exception
     */
    public void update(SysEventLogType aSysEventLogType)
        throws Exception {
        if (aSysEventLogType.getId() == 0) {
            throw new Exception(
                "Can not update object data whith out primary key value");
        }

        super.doUpdate(aSysEventLogType);

        SysEventLogType tempObj = findById(aSysEventLogType.getId());

        if (tempObj != null) {
            PropertyUtils.copyProperties(aSysEventLogType, tempObj);
        }
    }

    /**
     * Batch Update Datas
     * @param aSysEventLogTypes[]
     * @throws Exception
     */
    public void batchUpdate(SysEventLogType[] aSysEventLogTypes)
        throws Exception {
        super.doBatchUpdate(aSysEventLogTypes);
    }

    /**
         * Update Data By Condictions
         * @param aSysEventLogType
         * @param aValueCriteria
         * @param aTransaction
         * @throws Exception
         */
    public void update(SysEventLogType aSysEventLogType,
        SysEventLogTypeDAOQueryBean aQueryBean) throws Exception {
        super.doUpdateByQuery(aSysEventLogType, aQueryBean);
    }

    /**
     * Update Data By Condictions
     * @param aQueryBean
     * @throws Exception
     */
    public void update(SysEventLogTypeDAOQueryBean aQueryBean)
        throws Exception {
        super.doUpdateByQuery(aQueryBean);
    }

    protected void checkNullValue(SysEventLogType aSysEventLogType)
        throws Exception {
        if (aSysEventLogType.getEventTypeCode() == null) {
            throw new Exception(
                "The SysEventLogType.eventTypeCode value is not allow NULL");
        }

        if (aSysEventLogType.getEventTypeName() == null) {
            throw new Exception(
                "The SysEventLogType.eventTypeName value is not allow NULL");
        }

        if (aSysEventLogType.getStatus() == null) {
            throw new Exception(
                "The SysEventLogType.status value is not allow NULL");
        }

        if (aSysEventLogType.getRemarks() == null) {
            throw new Exception(
                "The SysEventLogType.remarks value is not allow NULL");
        }

        if (aSysEventLogType.getEventContentTemplate() == null) {
            throw new Exception(
                "The SysEventLogType.eventContentTemplate value is not allow NULL");
        }

        if (aSysEventLogType.getEventDomainName() == null) {
            throw new Exception(
                "The SysEventLogType.eventDomainName value is not allow NULL");
        }
    }

    /**
     * Get Data By ID
     * @param  final long id         * @return  ${businessObject.name}
     * @throws Exception
     */
    public SysEventLogType findById(final long id) throws Exception {
        SysEventLogTypeDAOQueryBean queryBean = new SysEventLogTypeDAOQueryBean();

        SysEventLogTypeDAOQueryBean.Criteria criteria = queryBean.createCriteria();

        criteria.andIdEqualTo(id);

        //queryBean.setDistinct(true);
        SysEventLogType[] SysEventLogTypes = query(queryBean);

        if (SysEventLogTypes.length == 0) {
            return null;
        } else {
            return SysEventLogTypes[0];
        }
    }

    /**
         * Query Data
         * @param queryBean
         * @return SysEventLogType[]
         * @throws Exception
         */
    public SysEventLogType[] query(SysEventLogTypeDAOQueryBean queryBean)
        throws Exception {
        List result = super.doQuery(queryBean,
                new JdbcSysEventLogTypeRowMapper());

        return (SysEventLogType[]) result.toArray(new SysEventLogType[result.size()]);
    }

    /**
     * Query ${businessObject.name} Selective
     * @param queryBean
     * @return Map[]
     * @model
     * @throws Exception
     */
    public Map<String, Object>[] querySelective(
        SysEventLogTypeDAOQueryBean queryBean) throws Exception {
        if (queryBean.getSelectProperties().isEmpty()) {
            queryBean.addAllSelectProperties();
        }

        return super.doQuerySelective(queryBean);
    }

    /**
     * Query Data Count
     * @param queryBean
     * @return int
     * @throws Exception
     */
    public int queryCount(SysEventLogTypeDAOQueryBean queryBean)
        throws Exception {
        return super.doQueryCount(queryBean);
    }

    public void synchronize(SysEventLogType[] aSysEventLogTypes,
        SysEventLogTypeDAOQueryBean queryBean) throws Exception {
        daoHelper.synchronize(aSysEventLogTypes, queryBean);
    }

    public void synchronize(SysEventLogType[] aSysEventLogTypes,
        SysEventLogTypeDAOQueryBean queryBean,
        net.dao.IDataAccessInterface.ISynchronizeCallback<SysEventLogType> callBack)
        throws Exception {
        daoHelper.synchronize(aSysEventLogTypes, queryBean, callBack);
    }

    public static class JdbcSysEventLogTypeRowMapper implements RowMapper<SysEventLogType> {
        public SysEventLogType mapRow(ResultSet resultSet, int arg1)
            throws SQLException {
            SysEventLogType object = new SysEventLogType();

            int columnIndex = 1;

            int __dataType;

            try {
                Object id = null;

                id = resultSet.getObject(columnIndex++);

                object.setIdNull(resultSet.getBoolean(columnIndex++));

                if (id != null) {
                    setBeanValue(object, _DataObjectProperty.Id, id);
                }

                Object eventTypeCode = null;

                eventTypeCode = resultSet.getObject(columnIndex++);

                object.setEventTypeCodeNull(resultSet.getBoolean(columnIndex++));

                if (eventTypeCode != null) {
                    setBeanValue(object, _DataObjectProperty.EventTypeCode,
                        eventTypeCode);
                }

                Object eventTypeName = null;

                eventTypeName = resultSet.getObject(columnIndex++);

                object.setEventTypeNameNull(resultSet.getBoolean(columnIndex++));

                if (eventTypeName != null) {
                    setBeanValue(object, _DataObjectProperty.EventTypeName,
                        eventTypeName);
                }

                Object status = null;

                status = resultSet.getObject(columnIndex++);

                object.setStatusNull(resultSet.getBoolean(columnIndex++));

                if (status != null) {
                    setBeanValue(object, _DataObjectProperty.Status, status);
                }

                Object remarks = null;

                remarks = resultSet.getObject(columnIndex++);

                object.setRemarksNull(resultSet.getBoolean(columnIndex++));

                if (remarks != null) {
                    setBeanValue(object, _DataObjectProperty.Remarks, remarks);
                }

                Object eventContentTemplate = null;

                eventContentTemplate = resultSet.getObject(columnIndex++);

                object.setEventContentTemplateNull(resultSet.getBoolean(
                        columnIndex++));

                if (eventContentTemplate != null) {
                    setBeanValue(object,
                        _DataObjectProperty.EventContentTemplate,
                        eventContentTemplate);
                }

                Object eventDomainId = null;

                eventDomainId = resultSet.getObject(columnIndex++);

                object.setEventDomainIdNull(resultSet.getBoolean(columnIndex++));

                if (eventDomainId != null) {
                    setBeanValue(object, _DataObjectProperty.EventDomainId,
                        eventDomainId);
                }

                Object eventDomainName = null;

                eventDomainName = resultSet.getObject(columnIndex++);

                object.setEventDomainNameNull(resultSet.getBoolean(
                        columnIndex++));

                if (eventDomainName != null) {
                    setBeanValue(object, _DataObjectProperty.EventDomainName,
                        eventDomainName);
                }

                return object;
            } catch (Exception e) {
                throw new SQLException(e.getMessage());
            }
        }
    }
}
